package com.barry;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 类功能描述：
 *
 * @author WangXueXing create at 18-12-7 下午4:18
 * @version 1.0.0
 */
public class Test1 {

    private static boolean ifElse(int a, int b){
        if(a>b)
            return true;
        return false;
    }

    private static String get(String a){
        return "String";
    }

    private static String get(int a){
        return "int";
    }

    public static void main(String[] args) throws IOException {
        String reportUrl = "11712100_长_201812_"+System.currentTimeMillis()+".xlsx_725a2fd5-bad9-41de-9a0b-2f378a9607f0";
        String prefix = null;
        String suffix = null;
        if(reportUrl.getBytes().length == reportUrl.length()) {
            prefix = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
            suffix = ".xlsx";
        }else{
            String[] allFile = new String[]{".csv", ".zip", ".xlsx", ".xls"};
            String reportName = new String(reportUrl.substring(0, reportUrl.lastIndexOf('_')).getBytes("utf-8"),"iso-8859-1");
            int index = reportName.lastIndexOf('.');
            if(index >= 0){
                suffix = reportName.substring(reportName.lastIndexOf('.'));
            }
            List<String> list = Arrays.asList(allFile);
            if(!list.contains(suffix)){
                prefix =  new String(reportUrl.substring(0,reportUrl.lastIndexOf("_")).getBytes("utf-8"),"iso-8859-1");
                suffix = ".xlsx";
                if (reportUrl.contains("batch")){
                    suffix = ".zip";
                }
            } else {
                prefix = reportName.substring(0, reportName.lastIndexOf('_'));
            }
        }
        File localFile = File.createTempFile(prefix,suffix);
        System.out.println(prefix+suffix);
    }
}
